#include "lh_string.h"



LH_U16 GetStringNum(LH_C8 *pstring)
{
    LH_U16 i1 = 0;
    
    while(*(pstring + i1) != 0)
        i1 ++;
    
    return i1;
}



void StingConvNum(LH_U32 num, LH_S8 leng, LH_S8 dotp, LH_S8 *pbuff)
{
    LH_S8 NumChar1[20] = {0};
    LH_S8 Count1 = 0;
    LH_S8 Count2 = 0;
    
    if(num == 0)
    {
        if (dotp != 0) leng ++;
        for(; Count2 < leng; Count2 ++)
            pbuff[Count2] = '0';        
        if (dotp != 0) pbuff[leng-1-dotp] = '.';
        pbuff[Count2] = 0;
    }
    else
    {
        while(Count1 != leng + dotp)
        {
            NumChar1[Count1] = num%10 + '0';
            num /= 10;
            Count1 ++;
            if( (dotp != 0) && (Count1 == dotp) ) 
            {
                NumChar1[Count1] = '.';
                Count1 ++;
            }  
        }
        for(; Count1 < leng; Count1 ++)
            NumChar1[Count1] = '0';
        
        for(Count1--; Count1 >= 0; Count1 --)
        {
            pbuff[Count2] = NumChar1[Count1];
            Count2 ++;
        }
        pbuff[Count2] = 0;
    }
}



void StringCopy(LH_S8 *wbuff, LH_S8 *rbuff)
{
    LH_S16 i1 = -1;
    
    do
    {
        i1 ++;
        *(wbuff + i1) = *(rbuff + i1);
    }
    while(*(rbuff + i1) != 0);
}



LH_U16 GetNumFrStr(LH_S8 *str)
{
    LH_U16 i1 = 0;
    LH_U16 StrLen = 0;
    LH_U16 num = 0;
    
    while(*(str + StrLen) != 0)
        StrLen ++;
    
    do
    {
        StrLen --;
        
        if(*(str + StrLen) != '.')
        {
            num += (*(str + StrLen) - '0')*pow(10, i1);
            i1 ++;
        }
    }
    while(StrLen != 0);
    
    return num;
}


LH_S8 LH_CmpStr(LH_S8 *str1, LH_S8 *str2)
{
    while((*str1 != 0) && (*str2 != 0))
    {
        if (*str1 != *str2)
            break;
        str1 ++;
        str2 ++;
    }
    
    if ((*str1 == 0) && (*str2 == 0))
        return 1;
    else
        return 0;
}


void LH_StrAdd(LH_S8 *str1, LH_S8 *str2)
{
    while(*str1 != 0) str1 ++;
    while(*str2 != 0) *str1++ = *str2++;
    *str1 = 0;
}


void LH_StrRepLocAt(LH_U16 adr, LH_S8 *to_str, LH_S8 *fr_str)
{
    while (*fr_str++ != 0) *(to_str + adr) = *fr_str;
}


void LH_StrRepChAt(LH_CHAR ch, LH_S8 *to_str, LH_S8 *fr_str)
{
    while ((*to_str != ch) && (*to_str != 0)) to_str ++;
    if (*to_str != 0)
        while (*fr_str != 0) *to_str++ = *fr_str++;
}









